package com.me.brainlessbirds.actors.map;

import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.InputEvent;
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
import com.me.brainlessbirds.Assets;
import com.me.brainlessbirds.actors.zombies.Zombie.ZombieType;
import com.me.brainlessbirds.screens.GameScreen;

public class SpawnButton extends Actor
{
	protected TextureRegion	rgn	= new TextureRegion();

	public SpawnButton(final int row)
	{
		rgn = new TextureRegion(Assets.get().textureSpawn);

		setSize(64.0f, 64.0f);
		setOrigin(getWidth() / 2, getHeight() / 2);
		setPosition(32f, row - getHeight() / 2f);

		this.addListener(new ClickListener()
		{
			@Override
			public boolean touchDown(InputEvent event, float x, float y, int pointer, int button)
			{
				boolean rv = super.touchDown(event, x, y, pointer, button);
				GameScreen.get().spawnZombie(ZombieType.BRAINLESS, 32f, row);
				return rv;
			}
		});

		GameScreen.get().getScene().addActor(this);
	}

	@Override
	public void draw(SpriteBatch batch, float parentAlpha)
	{
		setX(getWidth() / 2 + GameScreen.get().camera.position.x - GameScreen.WIDTH / 2);
		batch.draw(rgn, getX(), getY() - 20f, getOriginX(), getOriginY(), getWidth(), getHeight(), getScaleX(), getScaleY(), getRotation());
	}
}
